/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 

*/

#ifndef _Bat_h_
#define _Bat_h_

/**
* file   Bat.h
* date   Sam 2 jan 2010 19:37:29 CET
* brief  TODO
*/

#include "BatPart.h"
#include <set>
using namespace std;

#define MAX_CHUNKS (7)
#define BAT_Y (640)

class Bat {
public:
  /** Constructor used when loading a level.
    * The bat is always x-centered. */
  Bat (int nchunks);
  ~Bat ();
  /** Change the number of chunks.
    * This happens when an option is selected. */
  void set_nchunks (int nchunks) {
    nchunks_ = nchunks;
  }
  /** Get the number of chunks. Used in narrowing/enlarging */
  int get_nchunks () {
    return nchunks_;
  }
  /** Set the sticky flag. When set to true,
    * the ball remains sticked to the bat until
    * the player press a button to launch it.
    * Defaults to 'true' for each new attempt/life.
    */
  void set_sticky (bool sticky) {
    sticky_ = sticky;
  }
  /** Change the X position of top left corner of the bat. */
  void set_x_position (int x);
  /** Blit all the components of the bat (borders and chunks). */
  void blit () {
    for (int k = 0; k < nchunks_+2; k++) {
      parts_[k]->blit();
    }
  }
  bool get_sticky () {
    return sticky_;
  }
  int get_x_position () {
    return x_;
  }
  void get_parts (set<GameObject*>& parts) {
    for (int k = 0; k < nchunks_+2; k++) {
      parts.insert(parts_[k]);
    }
  }
  const SDL_Rect* get_rect () {
    const SDL_Rect* lborder = parts_[0]->get_rect();
    rect_.x = lborder->x;
    rect_.y = lborder->y;
    rect_.w = 32 + nchunks_ * 16;
    rect_.h = 16;
    return &rect_;
  }
private:
  BatPart* parts_[16];
  /** Number of chunks (min:1 max:5).
    * A chunk is a central part of the bat. */
  int nchunks_;
  /** X position of the left corner of the bat.
    * The Y position is fixed. */
  int x_;
  /** Sticky flag: true when the ball remains
    * sticked to the bat. */
  bool sticky_;
  /** Display rectangle, calculated on demand */
  SDL_Rect rect_;
};

#endif

